using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace Assets.Scripts.Audio
{
    public class BGAudio : AudioBase
    {
        private void Awake()
        {
            Bind(AudioEvent.PLAY_BG_AUDIO,
                AudioEvent.SET_BG_AUDIO,
                AudioEvent.STOP_BG_AUDIO);
        }
        public override void Execute(int eventCode, object message)
        {
            switch (eventCode)
            {
                case AudioEvent.PLAY_BG_AUDIO:
                    playAudio();
                    break;
                case AudioEvent.SET_BG_AUDIO:
                    playVolume((float)message);
                    break;
                case AudioEvent.STOP_BG_AUDIO:
                    stopAudio();
                    break;
                default:
                    break;
            }
        }

        [SerializeField]
        private AudioSource audioSource;

        private void playAudio()
        {
            audioSource.Play();
        }

        private void playVolume(float value)
        {
            audioSource.volume = value;
        }

        private void stopAudio()
        {
            audioSource.Pause();
        }

    }
}
